<?php

namespace App\Http\Controllers\Web;

use App\Models\WebSiteConfig;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class WebSiteConfigController extends Controller
{
    public function index()
    {
        $query = WebSiteConfig::query()->first();

        return $this->success($query);
    }

    public function requestData(Request $request)
    {
        $requestData = $this->validate($request, [
            'title' => 'required',
            "keywords" => 'nullable',
            "description" => 'nullable',
            "record_number" => 'nullable',
            "copyright" => 'nullable',
        ]);
        return $requestData;
    }

    public function update(Request $request)
    {
        $requestData = $this->requestData($request);
        $webSiteConfig = WebSiteConfig::query()->first();
        if (!$webSiteConfig) {
            $webSiteConfig = new WebSiteConfig();
        }
        $webSiteConfig->fill($requestData);
        $webSiteConfig->save();
        return $this->success($requestData);
    }
}
